草庐IT

Spring boot项目出现500错误

全部标签

ruby-on-rails - 无方法错误 : undefined method `safe_constantize'

我有一个简单的模型:classPost它有一个名为type的INT列当我创建记录时:Post.create(:type=>1)我得到:NoMethodError:undefinedmethod`safe_constantize'for1:Fixnum我做错了什么? 最佳答案 就像这样:在Fixnum上没有名为safe_constantize的方法。type用于SingleTableInheritance.您通常会在应用程序中将已知模型的字符串表示形式作为type值。参见railsguides

ruby-on-rails - 如何在 Rails 中使用 Rspec stub 错误引发?

我是Rails和Rspec的新手,我正在使用Rspec来测试这个包含异常处理的Controller方法:defsearch_movies_director@current_movie=Movie.find(params[:id])begin@movies=Movie.find_movies_director(params[:id])rescueMovie::NoDirectorErrorflash[:warning]="#{@current_movie}hasnodirectorinfo"redirect_tomovies_pathendend我不知道如何正确测试上述路径:在无效搜索后

ruby-on-rails - 切换到 Rails 4.1 时出现错误 - `method_missing':ActiveRecord::Base:Class (NoMethodError) 的未定义方法 `whitelist_attributes='

从Rails4.0切换到Rails4.1时出现此错误:activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in`method_missing':undefinedmethod`whitelist_attributes='forActiveRecord::Base:Class(NoMethodError)我没有在我的应用程序的任何地方使用attr_accessible或attr_protected所以我想知道为什么我有问题。当迁移到Rails4.0时,我已经安装了我的application.rb:配置/应用程序.rb:c

ruby-on-rails - Ruby/RoR - 计算数组中元素的出现次数

我有一个哈希{1=>true,7=>false,6=>true,4=>false}或者像这样的数组[1,true],[7,false],[6,true],[4,false]]或[真、假、真、假]。如何找到数组中true的个数? 最佳答案 为了对元素进行计数,您显然必须遍历集合。由于遍历Hash会产生两个元素的Array,因此前两个实际上完全相同:{1=>true,7=>false,6=>true,4=>false}.count(&:last)[[1,true],[7,false],[6,true],[4,false]].count(

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby-on-rails - Bundler 将我的 gem 放在我的项目目录中

我在Ruby1.9.2上有一个运行良好的Rails3rc应用程序,但Bundler一直在我的项目目录中创建一个名为“bandsintown”的文件夹(bandsintown是我使用的gem)。据我所知,这个文件夹里有我所有的珍宝。我很确定这以前从未发生过。这是正常行为吗?我认为这可能会干扰正在运行的测试。我收到“命令失败,状态为(1)”错误,然后它多次提到“bandsintown”文件夹。我发现Bundler将文件夹命名为“bandsintown”很奇怪,即使我在gemfile中注释掉那个gem。那个文件夹中有一个“ruby”文件夹,“ruby”文件夹中有一个“1.9.1”文件夹。我不

ruby - 如何使用礼物?在 Ruby 项目中?

我写了一个脚本,它使用Rails对Ruby核心对象类的扩展,现在我想把它独立出来。除了重写这些,是否有任何库或扩展可以让我独立使用它们? 最佳答案 您不必运行Rails即可使用require'active_support/all'或者如果您只想要一个特定的扩展名,例如blank?用于字符串,那么就可以require'active_support/core_ext/string'我lookeduppresent?它实际上被定义为defpresent?!blank?end积极支持中的空白定义为defblank?respond_to?(:

ruby - 尝试从 FTP 下载文件导致 "500 Illegal PORT command"错误

如果我在本地执行,一切正常:require'net/ftp'ftp=Net::FTP.new("myftpserver.com","username","password")ftp.getbinaryfile("/myfile.zip","localfile.zip")ftp.close如果我尝试在我使用的Linux服务器上执行它,结果是:/usr/local/lib/ruby/1.9.1/net/ftp.rb:273:in`getresp':500IllegalPORTcommand.(Net::FTPPermError)from/usr/local/lib/ruby/1.9.1/n

ruby - 我在 Mac OS X 上收到 "RVM is not a function"错误,并且没有发布的解决方案有效

我在MacOSx10.8.2(“MountainLion”)上,我成功安装了RVM1.17.8及其依赖项。我可以使用它来使用rvminstall1.9.2安装Ruby版本,但我无法执行rvmuse没有收到此错误:RVMisnotafunction,selectingrubieswith'rvmuse...'willnotwork.Youneedtochangeyourterminalemulatorpreferencestoallowloginshell.Sometimesitisrequiredtouse`/bin/bash--login`asthecommand.Pleasevis

ruby - 如何捕获由对等方重置的错误连接 (Errno::ECONNRESET)

以下代码有时会生成“连接被对等方重置”错误。谁能告诉我如何处理这个异常?doc=Nokogiri::HTML(open(url))Connectionresetbypeer(Errno::ECONNRESET) 最佳答案 要捕获它,就像处理任何其他异常一样:begindoc=Nokogiri::HTML(open(url))rescueErrno::ECONNRESET=>eputs"wearehandlingit!"end更有用的模式是尝试几次,然后放弃:count=0begindoc=Nokogiri::HTML(open(ur